<?php
session_start();

require_once("../database.include.php");

	$username=$_GET["username"];
    
    $sql = "SELECT `invitation_id`, `inviting_user_name`, `group_name` FROM `group_invitation` WHERE `invited_user_name` = '" . $username . "' ORDER BY `invitation_id`";

    print "<input type='hidden' id='acceptID' value=''>";
    
    $stmt = $conn->prepare($sql);
	$stmt->execute();
	$count = $stmt->rowcount();
    
    if ($count > 0) {
	    echo "<table border='1'><tr><td>&nbsp;</td><td>ID</td><td>Inviting User</td><td>Group</td></tr>";
	    foreach ($conn->query($sql) as $row) {
	    	echo "<tr>";
	    	echo "<td><input type='radio' name='myinv' id='myinv' value='" . $row['invitation_id'] . "' onclick=document.getElementById('acceptID').value='" . $row['invitation_id'] . "';></td>";
	    	echo "<td>" . $row['invitation_id'] . "</td>";
	        echo "<td>" . $row['inviting_user_name'] . "</td>";
	        echo "<td>" . $row['group_name'] . "</td>";
	        echo "</tr>";
	    }
	    echo "</table>";
	    echo "count " . count($row) . "<br>";
		echo "<button onclick=acceptInvite()>Accept</button><button onclick=declineInvite()>Decline</button>";
	} else {
		echo "<p>No incoming invites.  Forever alone :(</p>";
	}
?>